using System;
using FJson;
using Framework.Save.Interface;
using Framework.Utils;
using MiniJSON;
using UnityEngine;

namespace Framework.Save
{
    public class SaveSerializerJson : ISaveSerializer
    {

        public byte[] Serialize(object obj)
        {
            var json = FJsonUtility.ToJson(obj);
            return FileHelper.StringToArrayByteUtf8(json);
        }

        public T Deserialize<T>(byte[] value)
        {
            if (value != null)
            {
                var json = FileHelper.ArrayByteUtf8ToString(value);
                return FJsonUtility.ToObject<T>(json); 
            }
            return default;
        }
    }
}